<?php
	class carpetasstatus extends Controller {
		public function __construct() {
			parent::Controller();
			$this->load->model('mcarpetastatus');
			$this->load->helper(array('form','url'));
			$this->load->library(array('upload','form_validation'));
			$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
		}

		function index() {
			$this->load->view('main', array('content_page' => 'estatusdocumentos_list','menutop' => 0));
		}
		
		function add(){
			$this->load->view('main', array('content_page' => 'companiastatusca','menutop' => 0));
		}
		
		function edit($id){
			$status = $this->mcarpetastatus->LoadEtapaById($id);
			
			$this->load->view('main', array('content_page' => 'companiacapetasstatus_edit','menutop' => 0,'status'=>$status));
		}

		
		function save(){
			$idioma = intval($this->input->post('idioma'));  			
			$data = array(
			               'descriccion'=>$this->input->post('name'),
			               'idIdioma'=>$idioma
			             );
		
			             $this->mcarpetastatus->add($data);	
			              	 
		    redirect('carpetasstatus');	  
			
		}
		
		function save2(){
					$idioma = intval($this->input->post('idioma'));  	
			      $data = array(
			               'descriccion'=>$this->input->post('name'),
			               'idIdioma'=>$idioma
			             );
		
			             $this->mcarpetastatus->edit($data,$this->input->post('id'));	
			              	 
		    redirect('carpetasstatus');

		}

		function data() {
			$page = $this->input->post('page') ? $this->input->post('page') : 1; // Pagina Actual o 1 por default
			$sortname = $this->input->post('sidx') ? $this->input->post('sidx') : 'ID_airport'; // Columna para el order by
			$sortorder = $this->input->post('sord') ? $this->input->post('sord') : 'asc'; // Orden (asc|desc)
			$limit = $this->input->post('rows') ? $this->input->post('rows') : 10;
			$start = $limit * $page - $limit;
			if($start < 0) $start = 0;

			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
			header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
			header("Cache-Control: no-cache, must-revalidate" );
			header("Pragma: no-cache" );

			$records = $this->mcarpetastatus->LoadStatusDocumento();

			$totalRecords = $this->mcarpetastatus->GetCount();

			$totalPages = ceil($totalRecords/$limit);
			if ($page > $totalPages) $page = $totalPages;

			$json_output = array(
				'page'		=> $page,
				'total'		=> $totalPages,
				'records'	=> $totalRecords,
				'rows'		=> array()
			);

			if($records != false) {
				foreach($records as $estatus) {
					
					      if ($estatus->getIdIdioma() == 1) {
					      	 $edioma = 'Espanol';
					      }else{
					      	$edioma = 'Ingles';
					      } 
					
					      $arr = $json_output['rows'][] = array(
					                                            'IdEstatus' => $estatus->getIdProceso(), 	
					                                            'DescricionStatus' => $estatus->getDescriccion(), 
					                                            'IdIdioma' => $edioma); 
				}
			}

			echo json_encode($json_output);
		}
	}
?>